<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>易班自动打卡</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li><a href="reCheckin.html">补签</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="about.html">关于</a></li>
            </ul>
        </div>
    </div>
</nav>


<div class="container">
    <div id="alert">

    </div>
    <div class="panel panel-default">
        <div class="panel-heading">易班自动打卡</div>
        <div class="panel-body">
            <p>晨午检都是自动的，填一次即可<br>
                为了保险，建议自行检查是否签到成功<br>
                填写邮箱会有邮件提醒<br>
                <span style="color: red">若我没签上你又不补签，造成的任何后果都不关我事啊</span><br>

                <a href="reCheckin.html">这里可以在规定的时间之外进行签到</a>
            </p>
            <hr>
            <form id="form">

               <!-- <div class="form-group">
                    <label for="uid">UID</label>
                    <input type="text" name="uid" class="form-control" id="uid" readonly="readonly">
                </div>-->

                <div class="form-group">
                    <label for="account">手机号</label>
                    <input type="text" name="account" class="form-control" id="account" placeholder="易班登录手机号">
                </div>
                <div class="form-group">
                    <label for="address">地址</label>
                    <input type="text" name="address" class="form-control" id="address" placeholder="易班账号密码">
                </div>

                <button type="button" class="btn" id="submit">提交</button>
                <button class="btn" type="button" id="get">查询</button>
            </form>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-body">
            还没开发呢
        </div>
    </div>
    <a href="https://www.beian.miit.gov.cn/">陕ICP备20012211号-1</a>
</div>

<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
    let uid;
    $("#get").click(function (){
        $.ajax({
            url:"user/selectByAccount",
            method:"get",
            dataType:"json",
            data: {"account":$("#account").val()},
            success:function (res){
                let user = res.data;
                $("#account").val(user.account);
                $("#address").val(user.address);
                uid = user.uid;
            },
            error:function (e){
              alert("我裂开了");
            }
        })
    })

    $("#submit").click(function (){
        $.ajax({
            url: "user/"+uid,
            method: "put",
            dataType: "json",
            data: $("#form").serializeArray(),
            success:function (res){
                if(res.code === 200){
                    $("#alert").html('<div class="alert alert-success" role="alert">'+res.message+'</div>');
                } else {
                    $("#alert").html('<div class="alert alert-danger" role="alert">'+res.code+","+res.message+'</div>');
                }
            }
        })
    })
</script>
</body>
</html>